<?php 
    
    // Associate each visibility type to its corresponding tables    
    $visibility_types = array(
    "activity"             => array(   "story_table_name"       =>     "stories_activity",
                                       "operation_table_name"   =>     "operations_activity",
                                       "story_order_by"         =>     "order by activity desc",
                                       "is_show_number"         =>     false),
                                       
    "fixed"                => array(   "story_table_name"       =>     "stories_fixed",
                                       "operation_table_name"   =>     "operations_fixed",
    								   "story_order_by"         =>     "",
    								   "is_show_number"         =>     false),
    								   
    "popularity"           => array(   "story_table_name"       =>     "stories_popularity",
                                       "operation_table_name"   =>     "operations_popularity",
                                       "story_order_by"         =>     "order by popularity desc",
                                       "is_show_number"         =>     false),
                                       
    "random"               => array(   "story_table_name"       =>     "stories_random",
                                       "operation_table_name"   =>     "operations_random",
                                       "story_order_by"         =>     "random",
                                       "is_show_number"         =>     false),
                                       
    "activity_number"      => array(   "story_table_name"       =>     "stories_activity_number",
                                       "operation_table_name"   =>     "operations_activity_number",
                                       "story_order_by"         =>     "order by activity desc",
                                       "is_show_number"         =>     true),
                                       
    "fixed_number"         => array(   "story_table_name"       =>     "stories_fixed_number",
                                       "operation_table_name"   =>     "operations_fixed_number",
                                       "story_order_by"         =>     "",
                                       "is_show_number"         =>     true),
                                       
    "popularity_number"    => array(   "story_table_name"       =>     "stories_popularity_number",
                                       "operation_table_name"   =>     "operations_popularity_number",
                                       "story_order_by"         =>     "order by popularity desc",
                                       "is_show_number"         =>     true),
                                       
    "random_number"        => array(   "story_table_name"       =>     "stories_random_number",
                                       "operation_table_name"   =>     "operations_random_number",
                                       "story_order_by"         =>     "random",
                                       "is_show_number"         =>     true),
    );

function get_story_table_name($type) {
    global $visibility_types;
    return $visibility_types[$type]["story_table_name"];
}

function get_temp_operation_table_name($type){
    global $visibility_types;
    return 'tmp_'.$visibility_types[$type]["operation_table_name"];
}

function get_operation_table_name($type) {
    global $visibility_types;
    return $visibility_types[$type]["operation_table_name"];
}

function get_story_order_name($type) {
    global $visibility_types;
    return $visibility_types[$type]["story_order_by"];
}

function is_show_number($type) {
    global $visibility_types;
    return $visibility_types[$type]["is_show_number"];
}

function gen_visibility_type() {
    global $visibility_types;
    $keys = array_keys($visibility_types);
    //currently we want to hide recommendation numbers
    return $keys[rand(0, 3)];
}

?>